package cfca.seal.web.system;

import cfca.seal.bean.AdminUser;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class SessionManager
{
  private static final String MANAGER = "manager";
  private static final String URL_TYPE = "urlType";

  public static void saveManager(HttpServletRequest request, AdminUser manager)
  {
    if (null != manager)
      request.getSession().setAttribute("manager", manager);
  }

  public static AdminUser getManager(HttpServletRequest request)
  {
    Object object = request.getSession().getAttribute("manager");
    if (null == object) {
      return null;
    }
    return (AdminUser)object;
  }

  public static String getId(HttpServletRequest request)
  {
    Object object = request.getSession().getAttribute("manager");
    if (null == object) {
      return "";
    }
    return ((AdminUser)object).getId();
  }

  public static String getName(HttpServletRequest request)
  {
    Object object = request.getSession().getAttribute("manager");
    if (null == object) {
      return "";
    }
    return ((AdminUser)object).getName();
  }

  public static int getRoleLevel(HttpServletRequest request)
  {
    Object object = request.getSession().getAttribute("manager");
    if (null == object) {
      return 0;
    }
    return ((AdminUser)object).getUserType();
  }

  public static void saveUrlType(HttpServletRequest request, String urlType)
  {
    request.getSession().setAttribute("urlType", urlType);
  }

  public static String getUrlType(HttpServletRequest request)
  {
    Object object = request.getSession().getAttribute("urlType");
    if (null == object) {
      return null;
    }
    return (String)object;
  }
}